package com.szsfm.vehiclemanagement.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;

import com.szsfm.vehiclemanagement.activity.MainActivity;
import com.szsfm.vehiclemanagement.base.BaseActivity;
import com.szsfm.vehiclemanagement.base.BaseFragment;
import com.szsfm.vehiclemanagement.fragment.HomeFragment;
import com.szsfm.vehiclemanagement.fragment.MessageFragment;
import com.szsfm.vehiclemanagement.fragment.SettingFragment;
import com.szsfm.vehiclemanagement.fragment.VehicleFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhoubigbo on 2017/11/8.
 */
public class TabFragmentAdapter extends FragmentPagerAdapter {

    List<BaseFragment> mFragments = new ArrayList<>();

    public TabFragmentAdapter(BaseActivity ctx){
        super(ctx.getSupportFragmentManager());
        MainActivity mainActivity=(MainActivity)ctx;
        HomeFragment homeFragment = new HomeFragment();
        mainActivity.setActivityResultListener(homeFragment);
        addFragment(homeFragment);
        addFragment(new VehicleFragment());
        addFragment(new MessageFragment());
        addFragment(new SettingFragment());
    }



    public void addFragment(BaseFragment fragment){
        mFragments.add(fragment);
    }

    public List<BaseFragment> getFragment(){
        return mFragments;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    public BaseFragment itemWithID(int id){
        return mFragments.get(0);
    }

    @Override
    public int getCount() {
        return this.mFragments.size();
    }

}
